package com.miyake.dsp.osa.lab.wrapper;

import com.miyake.dsp.ComplexArray;
import com.miyake.dsp.osa.lab.Calculator;
import com.miyake.dsp.osa.lab.LabUiAnnotation;
import com.miyake.dsp.otdr.Otdr;
import com.miyake.dsp.otdr.OtdrImpulseResponseSetting;

@LabUiAnnotation(caption="OTDR Simulator")
public class OtdrWrapper extends Calculator {
	public static final String OUTPUT_X = "Distance";
	public static final String OUTPUT_Y = "Loss";
	
	private OtdrImpulseResponseSetting setting;

	public OtdrWrapper(OtdrImpulseResponseSetting setting) {
		this.setting = setting;
		initOutput(OUTPUT_X);
		initOutput(OUTPUT_Y);
	}
	
	@Override
	public synchronized void process() {
		Otdr otdr = new Otdr(setting);
		ComplexArray loss = otdr.getProcessed();
		this.setOutput(OUTPUT_Y, loss);
		int size = loss.getRealPart().length;
		double step = setting.getDistanceRange() / (double)size;
		double[] ret = new double[size];
		for (int i = 0; i < size; i++) {
			ret[i] = step * (double)i;
		}
		this.setOutput(OUTPUT_X, ret);
	}

	@Override
	public Object getSetting() {
		return setting;
	}

}
